package model

import (
	"gorm.io/gorm"
	__ "video-srv/basic/proto/rpc"
)

type Favorite struct {
	gorm.Model
	UserId  int `gorm:"type:int" json:"userId"`
	VideoId int `gorm:"type:int" json:"videoId"`
}

func (f *Favorite) AddFavorite(db *gorm.DB) error {
	return db.Create(&f).Error
}

func (f *Favorite) GetFavorite(db *gorm.DB, videoId int) (list []*__.VideoItem, err error) {
	err = db.Model(&f).Select("title,image,tags,refer,area_name,category_name,channel_name,year_name").
		Joins("left join videos on videos.id = favorites.video_id").
		Where("video_id = ?", videoId).Find(&list).Error
	return
}
